home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tclX-6.4 / help / intro / dollar < prev    next >
Encoding:
Text File  |  1992-12-17  |  3.3 KB  |  65 lines

  1.      VARIABLE SUBSTITUTION WITH $
  2.           The dollar sign ($) may be used as a special shorthand  form
  3.           for  substituting  variable  values.   If  $  appears  in an
  4.           argument  that  isn't  enclosed  in  braces  then   variable
  5.           substitution  will occur.  The characters after the $, up to
  6.           the  first  character  that  isn't  a  number,  letter,   or
  7.           underscore,  are  taken  as  a  variable name and the string
  8.           value of that variable is substituted  for  the  name.   For
  9.           example,  if  variable  foo  has  the  value  test, then the
  10.           command                                                     
  11.  
  12.                set a $foo.c                                           
  13.  
  14.           is equivalent to the command                                
  15.  
  16.                set a test.c                                           
  17.  
  18.  
  19.           There are two special forms for variable  substitution.   If
  20.           the next character after the name of the variable is an open
  21.           parenthesis, then the variable is assumed  to  be  an  array
  22.           name, and all of the characters between the open parenthesis
  23.           and the next close parenthesis are taken as  an  index  into
  24.           the array.  Command substitutions and variable substitutions
  25.           are performed on the  information  between  the  parentheses
  26.           before it is used as an index.  For example, if the variable
  27.           x is an array with one element named first and value 87  and
  28.           another element named 14 and value more, then the command   
  29.  
  30.                set a xyz$x(first)zyx                                  
  31.           is equivalent to the command                                
  32.  
  33.                set a xyz87zyx                                         
  34.  
  35.           If the variable index has the value 14, then the command    
  36.  
  37.                set a xyz$x($index)zyx                                 
  38.           is equivalent to the command                                
  39.  
  40.                set a xyzmorezyx                                       
  41.  
  42.           For more information on arrays,  see  VARIABLES  AND  ARRAYS
  43.           below.                                                      
  44.  
  45.           The second special form for variables occurs when the dollar
  46.           sign  is  followed by an open curly brace.  In this case the
  47.           variable name consists of all the characters up to the  next
  48.           curly  brace.   Array  references  are  not possible in this
  49.           form:  the name between braces is  assumed  to  refer  to  a
  50.           scalar variable.  For example, if variable foo has the value
  51.           test, then the command                                      
  52.  
  53.                set a abc${foo}bar                                     
  54.           is equivalent to the command                                
  55.  
  56.                set a abctestbar                                       
  57.  
  58.           Variable substitution does not occur in arguments  that  are
  59.           enclosed  in  braces:  the dollar sign and variable name are
  60.           passed through to the argument verbatim.
  61.  
  62.           The dollar sign abbreviation is simply a shorthand form.  $a
  63.           is  completely  equivalent  to  [set a]; it is provided as a
  64.           convenience to reduce typing.
  65.